package com.galaxy.samson.student.domain;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javax.persistence.*;

/**
 * Created by IntelliJ IDEA.
 * User: arunachalam
 * Date: 2/6/12
 * Time: 7:01 PM
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "Address")
public class Address
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column(nullable = false)
    private String doorNumber;
    @Column(nullable = false)
    private String street;
    @Column(nullable = false)
    private String city;
    @Column(nullable = false)
    private String district;
    @Column(nullable = false)
    private String state;
    @Column(nullable = false)
    private String pinCode;
    @Column(nullable = false)
    private String phoneNumber;
    @OneToOne
    private Student student;

    public Address()
    {
    }

    public Address(String doorNumber, String street, String city, String district, String state, String pinCode, String phoneNumber,Student student)
    {
        this.doorNumber = doorNumber;
        this.street = street;
        this.city = city;
        this.district = district;
        this.state = state;
        this.pinCode = pinCode;
        this.phoneNumber = phoneNumber;
        this.student=student;
    }

    public int getId()
    {
        return id;
    }

    public String getDoorNumber()
    {
        return doorNumber;
    }

    public void setDoorNumber(String doorNumber)
    {
        this.doorNumber = doorNumber;
    }

    public String getStreet()
    {
        return street;
    }

    public void setStreet(String street)
    {
        this.street = street;
    }

    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public String getDistrict()
    {
        return district;
    }

    public void setDistrict(String district)
    {
        this.district = district;
    }

    public String getState()
    {
        return state;
    }

    public void setState(String state)
    {
        this.state = state;
    }

    public String getPinCode()
    {
        return pinCode;
    }

    public void setPinCode(String pinCode)
    {
        this.pinCode = pinCode;
    }

    public String getPhoneNumber()
    {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber)
    {
        this.phoneNumber = phoneNumber;
    }


    public Student getStudent()
    {
        return student;
    }

    public void setStudent(Student student)
    {
        this.student = student;
    }

    @Override
    public int hashCode()
    {
        HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
        hashCodeBuilder.append(getId());
        hashCodeBuilder.append(getDoorNumber());
        hashCodeBuilder.append(getStreet());
        hashCodeBuilder.append(getCity());
        hashCodeBuilder.append(getDistrict());
        hashCodeBuilder.append(getPinCode());
        hashCodeBuilder.append(getState());
        hashCodeBuilder.append(getPhoneNumber());
        return hashCodeBuilder.hashCode();
    }

    @Override
    public boolean equals(Object o)
    {
        if(o instanceof Address)
        {
            Address otherObject = (Address)o;
            EqualsBuilder equalsBuilder = new EqualsBuilder();
            equalsBuilder.append(this.getId(),otherObject.getId());
            equalsBuilder.append(this.getDoorNumber(),otherObject.getDoorNumber());
            equalsBuilder.append(this.getStreet(),otherObject.getStreet());
            equalsBuilder.append(this.getCity(),otherObject.getCity());
            equalsBuilder.append(this.getDistrict(),otherObject.getCity());
            equalsBuilder.append(this.getPinCode(),otherObject.getDistrict());
            equalsBuilder.append(this.getState(),otherObject.getState());
            equalsBuilder.append(this.getPhoneNumber(),otherObject.getPhoneNumber()) ;
            return equalsBuilder.isEquals();
        }
        return false;
    }

    @Override
    public String toString()
    {
        ToStringBuilder stringBuilder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
        stringBuilder.append("id",getId());
        stringBuilder.append("doorNumber",getDoorNumber());
        stringBuilder.append("street",getStreet());
        stringBuilder.append("city",getStreet());
        stringBuilder.append("district",getDistrict());
        stringBuilder.append("pinCode",getPinCode());
        stringBuilder.append("state",getState());
        stringBuilder.append("phoneNumber",getPhoneNumber());
        return stringBuilder.toString();

    }
}
